package com.itheima.d01_api_period_duration;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;

public class Test2 {

    public static void main(String[] args) {
        //1.定义两个时间
        LocalDateTime start = LocalDateTime.of(2020, 5, 5, 10, 10, 10);
        LocalDateTime end = LocalDateTime.of(2020, 5, 5, 10, 20, 10);

        //2.获取时间间隔
        //2.1 获取时间间隔对象
        Duration between = Duration.between(start, end);

        //2.2 获取时间间隔
        System.out.println(between.toDays());//间隔天数
        System.out.println(between.toHours());//间隔小时
        System.out.println(between.toMinutes());//间隔分钟
        System.out.println(between.toSeconds());//间隔秒
        System.out.println(between.toMillis());//间隔毫秒
        System.out.println(between.toNanos());//间隔纳秒


        System.out.println("-----------------");
        //3.统计程序执行耗时

        Instant begin = Instant.now();

        String str = "";
        for (int i = 0; i < 100000; i++) {
            str += i;
        }

        Instant over = Instant.now();

        Duration between1 = Duration.between(begin, over);

        System.out.println("执行耗时："+between1.toMillis()+"ms");


    }
}
